package com.lap.auth.adapter.driving.query.dict.repository;

import com.lap.auth.adapter.driving.query.dict.DictTypeQueryConverter;
import com.lap.auth.adapter.driving.query.dict.mapper.DictTypeQueryMapper;
import com.lap.auth.adapter.driving.query.dict.po.DictTypePo;
import com.lap.auth.application.dict.dto.DictTypeDto;
import com.lap.auth.application.dict.dto.QueryDictTypePageQuery;
import com.lap.auth.application.dict.repository.DictTypeQueryRepository;
import com.lap.framework.dto.page.PageResponse;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

@RequiredArgsConstructor
@Repository
public class DictTypeQueryRepositoryImpl implements DictTypeQueryRepository {

  private final DictTypeQueryConverter converter;
  private final DictTypeQueryMapper dictTypeQueryMapper;

  @Override
  public PageResponse<DictTypeDto> findByConditionPaged(QueryDictTypePageQuery query) {
    long count = dictTypeQueryMapper.countPageByCondition(query);
    if (count == 0) {
      return PageResponse.ok(count);
    }
    List<DictTypePo> list = dictTypeQueryMapper.selectPageByCondition(query);
    return PageResponse.ok(converter.toDtoList(list), count);
  }
}
